#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
//using namespace std;

const char * select_word (const char **);

int main(int argc, const char *argv[])
{
    srand ((unsigned) time (NULL));

    const char * article[]     = {"the", "a", "one", "some", "any", NULL};
    const char * noun[]        = {"boy", "girl", "dog", "town", "car", NULL};
    const char * verb[]        = {"loved", "kissed", "killed", "drove", "jumped", "ran", "walked", "skipped", NULL};
    const char * preposition[] = {"of", "upon", "to", "from", "over", "under", "on", NULL};

    do 
    {
        char *first_word = strdup (select_word (article));
        *first_word = toupper (*first_word);
        printf ("%s %s %s %s %s %s.", first_word,
                                      select_word (noun),
                                      select_word (verb),
                                      select_word (preposition),
                                      select_word (article),
                                      select_word (noun)); 
        free (first_word);
    } while (fgetc (stdin) == '\n');

    return 0;
}

const char * select_word (const char **words)
{
    int count = 0;
    while (*(words++)) 
        count++;
    return (words-count-1)[rand () % count];
}
